<?php

include_once APPLICATION_DIR . "/application/model/TAGS.php";

class Tags extends DataObjects_TAGS
{
	function getList($filter = array(), &$pager=false)
	{
		$tags = new Tags();
		if (isset($filter['name']) && $filter['name']) {
			$tags->whereAdd("TAGS.NAME LIKE '%".mysql_escape_string($filter['name'])."%'");
		}
        $tags->selectAdd();
        $tags->selectAdd("TAGS.*");
		$tags->orderBy("TAGS.NAME");
		if ($pager == true) {
			$pager = new DBPager($tags, $filter, true);
		}
		
		$tags->find();

		return $tags;
	}

	function getTags($tags) {
        $arr_tags = array();
        $tags_names = "";
        if ($tags) {
            $tags_arr = explode(",", $tags);
            foreach ($tags_arr as $tags) {
                if ($tags) {
                    $arr_tags[] = $tags;
                }
            }
        }
        if ($arr_tags) {
            $tag_name = implode (",", $arr_tags); 
            $tags = new Tags();
            $tags->whereAdd("ID IN ({$tag_name})");
            $tags->orderBy("NAME");
            $tags->find();
            while($tags->fetch()) {
                if ($tags_names) {
                    $tags_names = $tags_names.", ".$tags->NAME;
                } else {
                    $tags_names = $tags->NAME;
                }
            }
        }
		return $tags_names;
	}
}
